<!--
// +----------------------------------------------------------------------
// | Copyright (c) 2017 https://gitee.com/honoryao All rights reserved.
// +----------------------------------------------------------------------
// | Author: honoryao <2463523099@qq.com>
// +----------------------------------------------------------------------
// | Time: 2018/6/8   
// +----------------------------------------------------------------------
-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Vue.directive 自定义指令</title>
</head>
<body>
<h1>Vue.directive 自定义指令</h1>
<hr>
<div id="app">
    <div v-jspang="color" id="demo">
        {{num}}
    </div>
    <div>
        <button @click="add">Add</button>
    </div>
    <div>
        <button onclick="unbind()">解除绑定</button>
    </div>
</div>

<script src="../assets/js/vue.js"></script>
<script>
    function unbind() {
        app.$destroy();
    }
    Vue.directive('jspang',{
        bind:function(el,binding){//被绑定
            console.log('1 - bind');
            el.style='color:'+binding.value;
        },
        inserted:function(){//绑定到节点
            console.log('2 - inserted');
        },
        update:function(){//组件更新
            console.log('3 - update');
        },
        componentUpdated:function(){//组件更新完成
            console.log('4 - componentUpdated');
        },
        unbind:function(){//解绑
            console.log('5 - unbind');
        }});

    var app= new Vue({
        el:'#app',
        data:{
            num:10,
            color:'red'
        },
        methods:{
            add:function(){
                this.num++;
            }
        }
    });
</script>
</body>
</html>